<?php
/**
 * Description:app端视频广告列表
 * Author: hezhizheng
 * Date: 2018/6/19
 * Time: 14:22
 * Created by Created by Panxsoft.
 */

namespace App\Http\Controllers\App;

use App\Http\Controllers\ApiController;
use App\Services\Utils\Guard;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class AdvertController extends ApiController
{

    const ROUTE = [
        'index' => 'api.app.advert.index'
    ];

    /**
     * @test
     *
     * @return array|\Illuminate\Http\Response
     */
    public function index()
    {
        $device_account = Guard::deviceAccount();

        $adverts = $device_account->adverts()
            ->with([
                'advertType'     => function (BelongsTo $builder) {
                    return $builder->select(['id', 'name']);
                },
                'redirectable'
            ])
            ->latest()
            ->get();

        return $this->response(compact('adverts'));
    }
}